<% content_for :page_title do %>
  <%= Spree.t(:general_settings) %>
<% end %>

<%= form_tag admin_general_settings_path, method: :put do %>
  <div id="preferences" data-hook>

    <fieldset class="general no-border-top">

      <%= fields_for :store do |f| %>
        <div class="row">
          <div class="col-md-6">
            <div class="form-group" data-hook="admin_general_setting_input_name">
              <%= f.label :name %>
              <%= f.text_field :name, class: 'form-control' %>
            </div>
          </div>

          <div class="col-md-6">
            <div class="form-group" data-hook="admin_general_setting_input_seo_title">
              <%= f.label :seo_title %>
              <%= f.text_field :seo_title, class: 'form-control'  %>
            </div>
          </div>
        </div>

        <div class="row">
          <div class="col-md-6">
            <div class="form-group" data-hook="admin_general_setting_input_meta_keywords">
              <%= f.label :meta_keywords %>
              <%= f.text_field :meta_keywords, class: 'form-control'  %>
            </div>
          </div>

          <div class="col-md-6">
            <div class="form-group" data-hook="admin_general_setting_input_meta_description">
              <%= f.label :meta_description %>
              <%= f.text_field :meta_description, class: 'form-control'  %>
            </div>
          </div>
        </div>

        <div class="row">
          <div class="col-md-6">
            <div class="form-group" data-hook="admin_general_setting_input_url">
              <%= f.label :url %>
              <%= f.text_field :url, class: 'form-control'  %>
            </div>
          </div>

          <div class="col-md-6">
            <div class="form-group" data-hook="admin_general_setting_mail_from_address">
              <%= f.label :mail_from_address %>
              <%= f.text_field :mail_from_address, class: 'form-control'  %>
            </div>
          </div>
        </div>
      <% end %>

      <div class="row">
        <div class="col-md-6">
          <%#-------------------------------------------------%>
          <%# Security settings                               %>
          <%#-------------------------------------------------%>
          <% if @preferences_security.any? %>
            <div class="panel panel-default security">
              <div class="panel-heading">
                <h1 class="panel-title">
                  <%= Spree.t(:security_settings) %>
                </h1>
              </div>

              <div class="panel-body">
                <% @preferences_security.each do |key|
                    type = Spree::Config.preference_type(key) %>
                    <div class="checkbox">
                      <%= label_tag key do %>
                        <%= preference_field_tag(key, Spree::Config[key], type: type) %>
                        <%= Spree.t(key) %>
                      <% end %>
                    </div>
                <% end %>
              </div>
            </div>
          <% end %>

          <%#-------------------------------------------------%>
          <%# Clear cache                                     %>
          <%#-------------------------------------------------%>
          <div class="panel panel-default">
            <div class="panel-heading">
              <h1 class="panel-title"><%= Spree.t(:clear_cache)%></h1>
            </div>

            <div class="panel-body">
              <div class="clear-cache-warning alert alert-warning">
                <%= Spree.t(:clear_cache_warning) %>
              </div>
              <div data-hook="general_settings_clear_cache">
                <%= button Spree.t(:clear_cache), 'ok', 'button', id: "clear_cache" %>
              </div>
            </div>
          </div>

        </div>
        <div class="col-md-6">

          <%#-------------------------------------------------%>
          <%# Currency Settings                               %>
          <%#-------------------------------------------------%>
          <div class="panel panel-default currency">
            <div class="panel-heading">
              <h1 class="panel-title">
                <%= Spree.t(:currency_settings)%>
              </h1>
            </div>

            <div class="panel-body">
              <div class="form-group">
                <%= label_tag :currency, Spree.t(:choose_currency) %>
                <%= select_tag :currency, currency_options %>
              </div>
            </div>
          </div>
        </div>
      </div>

      <div class="form-actions" data-hook="buttons">
        <%= button Spree.t('actions.update'), 'save' %>
        <span class="or"><%= Spree.t(:or) %></span>
        <%= button_link_to Spree.t('actions.cancel'), edit_admin_general_settings_url, icon: 'delete' %>
      </div>

    </fieldset>

  </div>

<% end %>

<script>
  $('#store_default_currency').select2();
  $('#currency').select2();
</script>
